#include <bits/stdc++.h>

using namespace std;

const int MOD = 10000;

int main()
{
    int a0, a1, p, q, k, res;

    cin >> a0 >> a1 >> p >> q >> k;

    for(int i = 0; i < k - 1; i++)
    {
        res = (p * a1 + q * a0) % MOD;
        a0 = a1;
        a1 = res;
    }

    cout << res % MOD << endl;

    return 0;
}
